package com.spiden.bazaspiden.pipeline;

import com.spiden.bazaspiden.mapper.FarmerMapper;
import com.spiden.bazaspiden.model.Farmer;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import javax.annotation.Resource;

/**
 * @author 张高昌
 * @version 1.0
 * @date 2024/1/10 14:44
 */
@Component
public class FarmerPipeline implements Pipeline {

    @Resource
    private FarmerMapper farmerMapper;

    @Override
    public void process(ResultItems resultItems, Task task) {
        String title = resultItems.get("title");
        String context = resultItems.get("content");
        Farmer farmer = new Farmer();
        if (title != null) {
            farmer.setTitle(title);
            farmer.setContent(context);
            farmerMapper.insertSelective(farmer);
        }
    }
}
